package com.biannuo.szk.demo.consumer.controller;

import com.biannuo.szk.common.base.BaseResponse;
import com.biannuo.szk.common.bean.ComplexObject;
import com.biannuo.szk.common.bean.Params;
import com.biannuo.szk.common.bean.Result;
import com.biannuo.szk.demo.consumer.service.DemoConsumerService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 消费者
 *
 * @author szk
 */
@RestController
@RequestMapping("/api/demoConsumer")
public class DemoConsumerController extends BaseResponse {
    @Resource
    private DemoConsumerService demoConsumerService;

    @RequestMapping("/openFeignTest")
    public String openFeignTest() {
        return demoConsumerService.openFeignProviderTest();
    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test() {
        return "success";
    }

    @RequestMapping("/sampleParamsTest")
    public String sampleParamsProviderTest() {
        return demoConsumerService.sampleParamsProviderTest("ZhangSan", 1);
    }

    @RequestMapping("/springQueryMapTest")
    public String springQueryMapTest() {
        // 参数
        Params params = new Params();
        params.setId(1);
        params.setName("ZhangSan");
        return demoConsumerService.springQueryMapProviderTest(params);
    }

    /**
     * 传递复杂对象的方法
     *
     * @return
     */
    @RequestMapping("/complexObjectTest")
    public Result complexObjectTest() {
        ComplexObject object = new ComplexObject();
        Params params = new Params();
        params.setName("ZhangSan");
        params.setId(1);
        object.setParams(params);
        Params params1 = new Params();
        params1.setName("123");
        // 调用服务提供者接口
        return demoConsumerService.complexObjectProviderTest(object);
    }

    @RequestMapping("/complexObjectTestException")
    public Result complexObjectTestException() {
        ComplexObject object = new ComplexObject();
        Params params = new Params();
        params.setName("ZhangSan");
        params.setId(1);
        object.setParams(params);
        Params params1 = new Params();
        params1.setName("123");

        Params params4 = new Params();
        params.setId(4);
        params.setName("Li4");

        // 调用服务提供者接口
        return demoConsumerService.complexObjectProviderTest(object, params4);
    }
}